package com.jxs.android.sxyw;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.jxs.android.sxyw.weiget.PopMsg;
import com.jxs.android.sxyw.weiget.TopBar;
import com.jxs.android.util.KeyboardUtil;
import com.jxs.android.util.StringUtils;

public class DescriptionSubmit extends AbstractActivity implements OnClickListener {
	private Button description_sumbit;
	private EditText descEditText;
	private TopBar topBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		initTopBar(savedInstanceState, R.layout.decription);
		descEditText = ((EditText) findViewById(R.id.decription_input));
		description_sumbit = (Button) findViewById(R.id.description_sumbit);
		description_sumbit.setOnClickListener(this);

		if (null != getIntent() && null != getIntent().getExtras()) {
			descEditText.setText(getIntent().getExtras().getString("desc"));
			topBar.setTitle(getIntent().getExtras().getString("title"));
			int length = getIntent().getExtras().getInt("length", 300);
			InputFilter[] filters = { new LengthFilter(length) };
			descEditText.setFilters(filters);
			descEditText.setHint(getString(R.string.input_limit_lenght_hint, "" + length));
		}
	}

	@Override
	public void onClick(View view) {

		String value = descEditText.getText().toString();
		if (StringUtils.isEmpety(value)) {
			PopMsg.show("请输入描述信息");
		} else {
			KeyboardUtil.hideIme(this);
			Intent intent = new Intent();
			Bundle bundle = new Bundle();
			bundle.putString("desc", value);
			intent.putExtras(bundle);
			setResult(RESULT_OK, intent);
			this.finish();
		}
	}

	@Override
	public void topBarLogic(TopBar topBar1) {
		this.topBar = topBar1;
		topBar.hindBtn();
		topBar.setTitle(R.string.description_submit_title_label);
		initTopBarReturn(topBar);
	}

}
